package cn.xscrum.vtsp.service.impl;

import java.util.List;
import cn.xscrum.common.utils.DateUtils;
import cn.xscrum.vtsp.mapper.VtspMessageMapper;
import cn.xscrum.vtsp.service.IVtspMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.xscrum.vtsp.mapper.VtspAdviceMapper;
import cn.xscrum.vtsp.domain.VtspAdvice;
import cn.xscrum.vtsp.service.IVtspAdviceService;
import cn.xscrum.common.core.text.Convert;

/**
 * 活动咨询记录Service业务层处理
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Service
public class VtspAdviceServiceImpl implements IVtspAdviceService 
{
    @Autowired
    private VtspAdviceMapper vtspAdviceMapper;

    @Autowired
    private IVtspMessageService vtspMessageService;

    /**
	 * 查询活动咨询记录
     * 
     * @param adviceId 活动咨询记录ID
     * @return 活动咨询记录
     */
    @Override
    public VtspAdvice selectVtspAdviceById(Long adviceId)
    {
        return vtspAdviceMapper.selectVtspAdviceById(adviceId);
    }

    /**
	 * 查询活动咨询记录列表
     * 
     * @param vtspAdvice 活动咨询记录
     * @return 活动咨询记录
     */
    @Override
    public List<VtspAdvice> selectVtspAdviceList(VtspAdvice vtspAdvice)
    {
        return vtspAdviceMapper.selectVtspAdviceList(vtspAdvice);
    }

    /**
	 * 新增活动咨询记录
     * 
     * @param vtspAdvice 活动咨询记录
     * @return 结果
     */
    @Override
    public int insertVtspAdvice(VtspAdvice vtspAdvice)
    {
        vtspAdvice.setCreateTime(DateUtils.getNowDate());
        return vtspAdviceMapper.insertVtspAdvice(vtspAdvice);
    }

    /**
	 * 修改活动咨询记录
     * 
     * @param vtspAdvice 活动咨询记录
     * @return 结果
     */
    @Override
    public int updateVtspAdvice(VtspAdvice vtspAdvice)
    {
        vtspAdvice.setUpdateTime(DateUtils.getNowDate());
        //回答活动咨询，更新到数据库
        int row = vtspAdviceMapper.updateVtspAdvice(vtspAdvice);
        //查询活动咨询的相关信息
        VtspAdvice advice = vtspAdviceMapper.selectVtspAdviceById(vtspAdvice.getAdviceId());
        //如果状态为已解决状态，添加一条消息持久化记录，用于移动端消息(活动咨询-1，活动id，消息消费者)
        if (vtspAdvice.getState() == 1){
            vtspMessageService.sendMessage(1,advice.getAdviceId(),advice.getVolunteerId());
        }
        return row;
    }

    /**
	 * 删除活动咨询记录对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteVtspAdviceByIds(String ids)
    {
        return vtspAdviceMapper.deleteVtspAdviceByIds(Convert.toStrArray(ids));
    }

    /**
	 * 删除活动咨询记录信息
     * 
     * @param adviceId 活动咨询记录ID
     * @return 结果
     */
    @Override
    public int deleteVtspAdviceById(Long adviceId)
    {
        return vtspAdviceMapper.deleteVtspAdviceById(adviceId);
    }
}
